import resources.RegistNetPropertyBundle;

import registnet.records.summary.delinquency.WarningDelinquency;
import registnet.records.summary.delinquency.source.WarningDelinquencySource;
import registnet.records.summary.delinquency.ProbationDelinquency;
import registnet.records.summary.delinquency.source.ProbationDelinquencySource;
import registnet.records.summary.delinquency.DismissalDelinquency;
import registnet.records.summary.delinquency.source.DismissalDelinquencySource;
import registnet.records.summary.delinquency.PermanentDisqualificationDelinquency;
import registnet.records.summary.delinquency.source.PermanentDisqualificationDelinquencySource;
import registnet.records.summary.delinquency.IScholarshipDelinquency;
import registnet.records.source.CollegeSource;
import registnet.records.College;
import registnet.records.Student;
import registnet.records.Grade;
		
import registnet.dao.GradePeer;
import registnet.dao.CoursePeer;
		
import resources.Constants;

/* [start] 	initializes gui variables */
RegistNetPropertyBundle bundle = RegistNetPropertyBundle.getInstance("/resources/registnet");

String _academic_year = bundle.getProperty("registnet.module.summary.macro.delinquency.search.academic_year");
String _semester = bundle.getProperty("registnet.module.summary.macro.delinquency.search.semester");

String _student_number = bundle.getProperty("registnet.module.summary.macro.delinquency.form.student_number");
String _full_name = bundle.getProperty("registnet.module.summary.macro.delinquency.form.full_name");
String _sex = bundle.getProperty("registnet.module.summary.macro.delinquency.form.sex");
String _college = bundle.getProperty("registnet.module.summary.macro.delinquency.form.college");
String _degree_course = bundle.getProperty("registnet.module.summary.macro.delinquency.form.degree_course");
String _delinquency = bundle.getProperty("registnet.module.summary.macro.delinquency.form.delinquency");

/* [end] */		



/* [start]	defines a renderer for the grades */
private class DelinquencyRenderer implements RowRenderer  {
	public void render(Row row, java.lang.Object data) {
		if (data[0] != null){
			new Label(data[0]).setParent(row);
			new Label(data[1]).setParent(row);
			new Label(data[2]).setParent(row);
			new Label(data[3]).setParent(row);
			new Label(data[4]).setParent(row);
			new Label(data[5]).setParent(row);
		}
		else{
			row.setVisible(false);
		}
	}
}
/* [end] */



/* [start] 	retrieves the grades and places them on the listbox */
void retrieveObjects(){
	try{
		Integer semesterValue = Constants.MAP_SEMESTER_KEY.get(semester.getSelectedItem().getLabel());
		Integer yearValue;
		if (semesterValue == Constants.MAP_SEMESTER_KEY.get(Constants.SUMMER))
			yearValue = Integer.parseInt(year2.value);
		else
			yearValue = Integer.parseInt(year1.value);
		
		IScholarshipDelinquency delinquencyList;
		
		if (delinquency_type.getSelectedItem().getLabel().equals(Constants.WARNING)){
			if (_user_type.equals(Constants.REGISTRAR))
				delinquencyList = (WarningDelinquency)new WarningDelinquencySource(semesterValue, yearValue).getDelinquencyList();
			else if (_user_type.equals(Constants.COLLEGE)){
				College college = new CollegeSource(_office).getCollege();
				delinquencyList = (WarningDelinquency)new WarningDelinquencySource(college, semesterValue, yearValue).getDelinquencyList();
			}
		}
		else if (delinquency_type.getSelectedItem().getLabel().equals(Constants.PROBATION)){
			if (_user_type.equals(Constants.REGISTRAR))
				delinquencyList = (ProbationDelinquency)new ProbationDelinquencySource(semesterValue, yearValue).getDelinquencyList();
			else if (_user_type.equals(Constants.COLLEGE)){
				College college = new CollegeSource(_office).getCollege();
				delinquencyList = (ProbationDelinquency)new ProbationDelinquencySource(college, semesterValue, yearValue).getDelinquencyList();
			}
		}
		else if (delinquency_type.getSelectedItem().getLabel().equals(Constants.DISMISSAL)){
			if (_user_type.equals(Constants.REGISTRAR))
				delinquencyList = (DismissalDelinquency)new DismissalDelinquencySource(semesterValue, yearValue).getDelinquencyList();
			else if (_user_type.equals(Constants.COLLEGE)){
				College college = new CollegeSource(_office).getCollege();
				delinquencyList = (DismissalDelinquency)new DismissalDelinquencySource(college, semesterValue, yearValue).getDelinquencyList();
			}
		}
		else if (delinquency_type.getSelectedItem().getLabel().equals(Constants.PERMANENT_DISQUALIFICATION)){
			if (_user_type.equals(Constants.REGISTRAR))
				delinquencyList = (PermanentDisqualificationDelinquency)new PermanentDisqualificationDelinquencySource(semesterValue, yearValue).getDelinquencyList();
			else if (_user_type.equals(Constants.COLLEGE)){
				College college = new CollegeSource(_office).getCollege();
				delinquencyList = (PermanentDisqualificationDelinquency)new PermanentDisqualificationDelinquencySource(college, semesterValue, yearValue).getDelinquencyList();
			}
		}	
		
		Iterator iter = delinquencyList.getDelinquencyList().keySet().iterator();
		String[][] listModel = new String[delinquencyList.getDelinquencyList().size()][6];
		int i=0;
		while(iter.hasNext()){
			Student student = iter.next();
			listModel[i][0] = "" + (i + 1);
			listModel[i][1] = student.getStudentNumber();
			listModel[i][2] = student.getLastName() + " " + student.getFirstName() + " " + student.getMiddleName();
			listModel[i][3] = student.getSex();
			listModel[i][4] = student.getCurriculum().getDegreeProgram().getCollege().getCollegeCode();
			listModel[i][5] = student.getCurriculum().getDegreeProgram().getDegreeCode();
			i++;
		}
		
		ListModel strset = new SimpleListModel(listModel);
		contents_win.getFellow("delinquency_g").setModel(strset);
		contents_win.getFellow("delinquency_g").setRowRenderer(new DelinquencyRenderer());
	} catch(Exception e){
		alert("Check information supplied");
	}
}
/* [end] */



/* [start]	defines a renderer for the grades */
public class SectionRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		new Listcell(data).setParent(item);
	}
}
/* [end] */



/* [start]	automatically updates the 'to' value of academic year based on the
			current 'from' value of the academic year */
private void updateAY(){
	try{
		year2.value = (Integer.parseInt(event.value) + 1).toString();
	}catch(Exception e) {year1.value = null; year2.value = null;}
}
/* [end] */
